﻿using UnityEngine;
using UnityEngine.UI;

namespace FutureCorePlugin
{
    [RequireComponent(typeof(Toggle))]
    public class UIToggle : MonoBehaviour
    {
        [SerializeField]
        private GameObject reOnObj;
        [SerializeField]
        private GameObject onObj;
        [HideInInspector]
        public Toggle toggle;

        private void Awake()
        {
            toggle = GetComponent<Toggle>();
            toggle.onValueChanged.AddListener(SetOn);
        }

        private void OnDestroy()
        {
            toggle.onValueChanged.RemoveListener(SetOn);
        }

        private void SetOn(bool isOn)
        {
            if (onObj != null && reOnObj != null)
            {
                onObj.SetActive(isOn);
                reOnObj.SetActive(!isOn);
            }
        }
    }
}